/**
 * 个人中心
 * @author  Jello
 * @create  2018/10/17 09:00
 * @version 1.0
 * @company 广东蓝聘科技网络有限公司
 **/
var sessionStorage = window.sessionStorage;
var localStorage = window.localStorage;
var money_show_status = localStorage.getItem("money_show_status");
var money_hide_status = localStorage.getItem("money_hide_status");
var userid_sign = ""; //获取用户登录状态
var work_status = "";
var user_money = "";
var spinner = new Spinner(opts);

$(function() {
	userid_sign = sessionStorage.getItem("userid_sign");
	//检测用户登录状态
	backLogin(userid_sign, "../../login.html", function() {
		//检测账户余额状态
		if(money_show_status) {
			$("#money_show").css("display", "none");
			$("#money_hide").css("display", "block");
			$("#money").css({
				"font-size": "0.8rem",
				"line-height": "170%"
			});
		} else if(money_hide_status) {
			$("#money_show").css("display", "block");
			$("#money_hide").css("display", "none");
		}

		//获取个人资料
		var param = {};
		param.userid_sign = userid_sign;
		getUserMaterial(param, function(data) {
			var user_url = data.user_url;
			var user_name = data.user_name;
			var user_sex = data.user_sex;
			work_status = data.workStatus;
			user_money = toDecimal(data.money);
			var role = data.role; //角色
			//头像
			if(user_url == "" || user_url == null) {
				$("#user_url").attr("src", "../../img/personal/personalh5_04.png");
			} else {
				$("#user_url").attr("src", user_url);
			}
			//性别
			if(user_sex == 0 || user_sex == 1) { //男
				$("#man_img").css("display", "block");
			} else {
				$("#woman_img").css("display", "block");
			}
			//昵称
			$("#nickname").html(user_name);
			//余额
			if(money_show_status != null) {
				$("#money").html(money_show_status);
			} else {
				$("#money").html(user_money);
			}
			//工作状态
			var temp = "";
			if(work_status == 0) {
				temp = "待业";
			} else if(work_status == 1) {
				temp = "在职";
			} else {
				temp = "入职中";
			}
			$("#user_status").html(temp);

			sessionStorage.setItem("user_url", user_url);
			sessionStorage.setItem("user_name", user_name);
			sessionStorage.setItem("user_sex", user_sex);
			sessionStorage.setItem("role", role);
		});
	});

	//账户余额显示数字
	$("#money_show").click(function() {
		$("#money_show").css("display", "none");
		$("#money_hide").css("display", "block");
		$("#money").html("***");
		$("#money").css({
			"font-size": "0.8rem",
			"line-height": "170%"
		});
		//本地存储记住用户点击的状态动态存储，下次进来以记住的这个key判断是否是显示或隐藏
		localStorage.setItem("money_show_status", $("#money").html());
		localStorage.removeItem("money_hide_status");
	})

	//账户余额显示***
	$("#money_hide").click(function() {
		$("#money_show").css("display", "block");
		$("#money_hide").css("display", "none");
		$("#money").css({
			"font-size": "0.45rem",
			"line-height": "1rem"
		});
		//获取个人资料
		var param = {};
		param.userid_sign = userid_sign;
		getUserMaterial(param, function(data) {
			$("#money").html(toDecimal(data.money)); //余额
		});
		localStorage.setItem("money_hide_status", 1);
		localStorage.removeItem("money_show_status");
	})

	//账单
	$("#bill").click(function() {
		toPage(userid_sign, "../../app/bill/personalbill.html", "../../login.html");
	})

	//工资卡管理
	$("#paycard").click(function() {
		toPage(userid_sign, "../../app/bank/paycardmanager.html", "../../login.html");
	})

	//面试预约
	$("#interview").click(function() {
		toPage(userid_sign, "../../app/work/interviewreservationlist.html", "../../login.html");
	})

	//邀请好友
	$("#invite").click(function() {
		toPage(userid_sign, "../../app/invite/invite_code.html", "../../login.html");
	})

	//离职通知
	$("#resignation").click(function() {
		toPage(userid_sign, "../../app/resignation/resignationinform.html", "../../login.html");
		sessionStorage.setItem("work_status", work_status);
	})

	//编辑
	$("#edit").click(function() {
		toPage(userid_sign, "../personal/personal_update.html", "../../login.html");
	})

	//ios提示框
	$("#version_ios").click(function() {
		$(".esc_divbox2").css("display", "none");
		$(".esc_box2").css("display", "none");
	})
})

/**
 * 提现
 */
function withdrawDeposit() {
	backLogin(userid_sign, "../../login.html", function() {
		//查询是否有银行卡，没有跳转银行卡页面，有直接到提现页面
		$.ajax({
			type: "get",
			url: serverUrl + "/billrecord/query_bankcardwithDraw?sgin=" + userid_sign,
			cache: false,
			async: false,
			contentType: "application/json; charset=utf-8",
			dataType: "json",
			timeout: 15000,
			crossDomain: true,
			success: function(data) {
				var resultObj = eval(data);
				if(resultObj.code == 0 && resultObj.data != null) {
					if(resultObj.data.type == 1) { //没有绑定银行卡
						window.location.href = "../../app/bank/addcard.html";
					} else {
						sessionStorage.setItem("with_bankname", resultObj.data.bankName);
						sessionStorage.setItem("with_banknumber", resultObj.data.bankNumber);
						sessionStorage.setItem("with_cardtype", resultObj.data.cardType);
						sessionStorage.setItem("reg_phone", resultObj.data.phone);
						window.location.href = "../../app/withdraw/withdraw.html";
					}
				} else {
					mui.toast(resultObj.msg);
					return;
				}
			},
			error: function(XMLHttpRequest, status, errorThrown) {
				if(status == 'timeout') {
					mui.toast("请求超时");
				} else {
					mui.toast("请求网络服务数据失败");
				}
				return;
			}
		});
	});
}

/**
 * 下载
 */
function uploadApp() {
	//	if(isiOS) {
	//		$(".esc_divbox2").css("display", "block");
	//		$(".esc_box2").css("display", "block");
	//	} else {
	//		window.location.href = "../../app/download/download_app.html";
	//	}
	window.location.href = "http://url.cn/5AUAFDU";
}